/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pedagio.negocio.base;

import java.io.Serializable;
import java.util.List;

/**
 *
 * @author pedroo
 */
  
public interface DefaultService <T, K extends Serializable> {
	
    /**
     * Creates a new object for the given type. After a call to this method the entity will be
     * persisted into database and then refreshed. Also current persistent Session will be flushed.
     * 
     * @param <T>
     * @param t
     * @return persisted Object
     */
    <T> T persist(T t);

    /**
     * Updates the given object
     * 
     * @param <T>
     * @param t
     * @return persisted object
     */
    <T> T update(T t);

    /**
     * Deletes the given object by object
     * 
     * @param <T>
     * @param id
     */
    void delete(T t);

     /**
     * Deletes the given object by id
     * 
     * @param <T>
     * @param id
     */
    <T, PK extends Serializable> void delete(PK id);

    /**
     * Finds an object by id
     * 
     * @param <T>
     * @param <PK>
     * @param type
     * @param id
     * @return the object
     */
    <T, PK extends Serializable> T find( PK id);
	
    /**
     * Invokes <code>entityManager().refresh()<code>.
     * @param object
     */
    void refresh(T object);

    /**
     * Attaches an object to the persistence context, if there is one. The object store
     * must not be changed. The attached object, which not necessarily is the one passed
     * as a parameter, is returned.
     * 
     * @param object a <code>T</code>.
     * @return object a <code>T</code>.
     */
    T attach(T object);

    /**
     * Removes an object from the persistence context, the object status will be
     * changed to transient
     * @param object a <code>T</code>.
     */
    void discard(T object);
    
    /**
     * Retorna todos os objetos
     * 
     * @return List a List of <code>T</code>
     */
    List<T> findAll();
	

}
